#!/usr/bin/python

import cgi
import sys
import json
import cgitb
import json



data1 = {"username": "blow, joe",
		"window": {"start": "0700 081514", "end": "1700 081514"},
		"times": [{"start": "0700 081514", "end": "0730 081514"},
				{"start": "1200 081514", "end": "1300 081514"},
				{"start": "1430 081514", "end": "1515 081514"}]}

data2 = {"userlist": [{"username": "blow, joe"},
					{"username": "smith, john"},
					{"username": "bob, billy"},
					{"username": "parker, peggy"}],
		"window": {"start": "0700 081514", "end": "1700 081514"},
		"attendees":[{"username": "bob, billy"},
					{"username": "parker, peggy"}]}

data23 = {"userlist": [{"username": "blow, joe"},
					{"username": "smith, john"},
					{"username": "bob, billy"},
					{"username": "parker, peggy"}],
		"window": {"start": "0700 081514", "end": "1700 081514"},
		"times": [{"start": "0700 081514", "end": "0730 081514"},
				{"start": "1430 081514", "end": "1515 081514"}],
		"attendees":[{"username": "bob, billy"},
					{"username": "parker, peggy"}]}		

class Provider:

	def __init__(self, reqData):
		self.reqData = reqData

	# right now, all this does is determine which option the
	# request is for so it knows what data to send back
	def parseRequest(self):
		pass
		# self.option = self.reqData['option'].value
		# self.option = self.reqData['option']

	def sendResponse(self):
		
		print("Content-Type: text/plain\n\n")
		cgitb.enable()
		print json.dumps(self.response)

	def getSolution(self):
		global data1
		global data2
		global data3

		self.response = data23

		# if self.option == "1":
		# 	self.response = data1

		# elif self.option == "2":
		# 	self.response = data2

		# elif self.option == "3":
		# 	self.response = data3
		# else:
		# 	self.response = ""



def main():

	# reqData = {
	# "option": "1", 
	# "username": "Blow, joe", 
	# "window": {
	# 	"start": "0700 081514",
	# 	"end": "1700 081514"
	# 	}
	# }

	reqData = cgi.FieldStorage()

	p = Provider(reqData)	
	p.parseRequest()
	p.getSolution()
	p.sendResponse()


if __name__ == "__main__":
    main()



